package com.acme.bankapp;

import com.acme.bankapp.domain.bank.*;
import com.acme.bankapp.domain.exceptions.ClientExistsException;
import com.acme.bankapp.service.bank.*;
import com.acme.bankapp.service.bank.email.EmailService;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by zurdan on 14.11.14.
 * E-mail: Zurdanium@gmail.com
 */
public class BankApplication {
    public static void main(String[] args) {

        Bank bank = new Bank();
        EmailService emailService = new EmailService();
        BankService.addListener(bank, new EmailNotificationListener(emailService));

        BankService.addListener(bank, new ClientRegistrationListener() {
            @Override
            public void onClientAdded(Client client) {
                System.out.println("From anonymous class:" + client.getSalutation());
            }
        });

        try {
            BankService.addClient(bank, new Client(new CheckingAccount(1623, 213123), "client11", Gender.MALE));

            Thread.sleep(1000);
            BankService.addClient(bank, new Client(new SavingsAccount(1223), "clientka", Gender.FEMALE));
            Thread.sleep(1000);

            BankService.addClient(bank, new Client(new SavingsAccount(666), "clientk2", Gender.FEMALE));
            Thread.sleep(1000);

            BankService.addClient(bank, new Client(new CheckingAccount(50, 100), "Hodor", Gender.MALE));
        } catch (ClientExistsException e) {
            System.err.println(e.getMessage());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        emailService.close();

    }

    private static Map<String, List<String>> findCommandArguments(String[] args) {
        String currentKey = null;
        HashMap<String, List<String>> map = new HashMap<>();
        for (String arg : args) {
            if (arg.startsWith("-")) {
                currentKey = arg;
                map.put(currentKey, new ArrayList<>());
            } else {
                if (currentKey != null) {
                    map.get(currentKey).add(arg);
                }
            }
        }
        return map;
    }
}
